package hong.jun.pet_home.controller.order;


import com.alibaba.fastjson.JSON;
import hong.jun.basic.util.AjaxResult;
import hong.jun.basic.util.PageList;
import hong.jun.basic.util.RedisUtils;
import hong.jun.pet_home.domain.org.Department;
import hong.jun.pet_home.domain.user.User;
import hong.jun.pet_home.query.DepartmentQuery;
import hong.jun.pet_home.service.order.IProductOrderService;
import hong.jun.pet_home.service.org.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * restfull风格
 *
 * @Controller
 * @ResponseBody
 */

@RestController
@RequestMapping("/productOrder")
//@CrossOrigin//后台的跨域解决方案-spring4.2.5及以上版本支持
public class ProductOrderController {
    @Autowired
    private IProductOrderService productOrderService;

    /**
     * 服务购买
     */
    @PostMapping("/pay")
    public AjaxResult pay(@RequestBody Map<String, Object> params, HttpServletRequest request) {
        try {
            User user = JSON.parseObject(RedisUtils.INSTANCE.get(request.getHeader("U-TOKEN")), User.class);
            String payData = productOrderService.payproduct(params, user);
            return AjaxResult.me().setResultObj(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.toString());
        }
    }

}
